/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bpmlab.shift.bean;

import bpmlab.shift.dao.DAOException;
import bpmlab.shift.dao.DAOFactory;
import bpmlab.shift.dao.service.GenericDAO;
import bpmlab.shift.entity.Nutriente;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author Mikael Lima
 */
@ManagedBean
@RequestScoped
public class NutrienteBean implements Serializable {

    private final GenericDAO<Nutriente> dao = DAOFactory.criarGenericDAO(Nutriente.class);
    private Nutriente nutriente = new Nutriente();
    private List<Nutriente> nutrientes;

    public String salvar() {
        try {
            dao.salvar(nutriente);
            JsfUtil.mensagemSalvoComSucesso();
            return "/admin/nutriente/lista-nutriente.xhtml";
        } catch (DAOException ex) {
            JsfUtil.mensagemErroAoSalvar();
            return null;
        }
    }

    public void excluir() {
        try {
            dao.excluir(nutriente);
            JsfUtil.mensagemRemovidoComSucesso();
        } catch (DAOException ex) {
            JsfUtil.mensagemErroAoRemover();
        }
    }

    public Nutriente getNutriente() {
        return nutriente;
    }

    public void setNutriente(Nutriente nutriente) {
        this.nutriente = nutriente;
    }

    public List<Nutriente> getNutrientes() {
        nutrientes = dao.obterTodos();
        return nutrientes;
    }

}
